package com.member.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.member.po.User;
import com.member.service.LoginService;

@Controller
public class LoginController {

	 @Autowired
	 LoginService loginService;
	// 登陆
	@RequestMapping("/login")
	public String login(HttpSession session,User user ,String username, String password)
			throws Exception {
		// 调用service进行用户身份验证		
        if(loginService.validation(user)){
        	// 在session中保存用户身份信息
    		session.setAttribute("username", username);
    		// 重定向到主页列表页面
    		return "redirect:/MainMenu";
        }else{
        	return "redirect:/login";
        }
		
	}

	// 退出
	@RequestMapping("/logout")
	public String logout(HttpSession session) throws Exception {

		// 清除session
		session.invalidate();

		// 重定向到商品列表页面
		return "redirect:/items/queryItems.action";
	}
	
   //主菜单页面
	@RequestMapping("/MainMenu")
	public String indexMainMenu(Model model,HttpServletRequest request)
	{
	     return "MainMenu";
	}
}
